﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DB_Connect
{
    abstract class DatabaseConnection
    {
        private string connectionString;
        private TimeSpan timeOut;

        public DatabaseConnection(string connectionPath, TimeSpan timeOut)
        {
            ConnectionString = connectionPath;
            TimeOut = timeOut;
        }

        public string ConnectionString
        {
            get
            {
                return connectionString;
            }
            private set
            {
                if (String.IsNullOrWhiteSpace(value))
                {
                    throw new ArgumentException("Incorrect path to connect.");
                }
                connectionString = value;
            }
        }

        public TimeSpan TimeOut
        {
            get
            {
                return timeOut;
            }
            set
            {
                timeOut = value;
            }
        }

        abstract public void OpenConnection();
        abstract public void CloseConnection();

    }

    class MsSqlConnection : DatabaseConnection
    {
        public MsSqlConnection(string connectionPath, TimeSpan timeOut) : base(connectionPath, timeOut)
        {
        }

        public override void OpenConnection()
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("DB MsSqlConnection is open.");
            Console.ForegroundColor = ConsoleColor.White;
        }

        public override void CloseConnection()
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("DB MsSqlConnection is closed.");
            Console.ForegroundColor = ConsoleColor.White;
        }

    }

    class MySqlConnection : DatabaseConnection
    {
        public MySqlConnection(string connectionPath, TimeSpan timeOut) : base(connectionPath, timeOut)
        {
        }

        public override void OpenConnection()
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("DB MySqlConnection is open.");
            Console.ForegroundColor = ConsoleColor.White;
        }

        public override void CloseConnection()
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("DB MySqlConnection is closed.");
            Console.ForegroundColor = ConsoleColor.White;

        }

    }
}
